package com.site.blog.my.core.service.impl;

import com.site.blog.my.core.controller.vo.BlogListVO;
import com.site.blog.my.core.dao.BlogMapper;
import com.site.blog.my.core.dao.TbBlogMapper;
import com.site.blog.my.core.entity.Blog;
import com.site.blog.my.core.entity.TbBlog;
import com.site.blog.my.core.entity.TbBlogExample;
import com.site.blog.my.core.repository.EsProductRepository;
import com.site.blog.my.core.service.EsProductService;
import com.site.blog.my.core.util.PageQueryUtil;
import com.site.blog.my.core.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Service
public class EsProductServiceImpl implements EsProductService {
    @Resource
    private TbBlogMapper tbBlogMapper;
    @Resource
    private BlogMapper blogMapper;

    @Autowired
    private EsProductRepository esProductRepository;
    @Override
    public Integer importEsBlog() {
        List<TbBlog> esProductList = tbBlogMapper.selectByExample(new TbBlogExample());
//        long i=0;
//        for(TbBlog t: esProductList){
//            t.setId(i++);
//        }
        Iterable iterable =esProductRepository.saveAll(esProductList);
        Iterator<TbBlog> iterator = iterable.iterator();
        int result = 0;
        while (iterator.hasNext()) {
            result++;
            iterator.next();
        }
        return result;
    }

    @Override
    public PageResult getBlogsForIndexPage(int page) {
//        Map params = new HashMap();
//        params.put("page", page);
//        //每页8条
//        params.put("limit", 8);
//        params.put("blogStatus", 1);//过滤发布状态下的数据
//        PageQueryUtil pageUtil = new PageQueryUtil(params);
//        List<Blog> blogList = blogMapper.findBlogList(pageUtil);
//        List<BlogListVO> blogListVOS = blogMapper.getBlogListVOsByBlogs(blogList);
//        int total = blogMapper.getTotalBlogs(pageUtil);
     //   PageResult pageResult = new PageResult(blogListVOS, total, pageUtil.getLimit(), pageUtil.getPage());
        return null;
    }
}
